package com.example;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

/**
 * Created by Administrator on 2018/5/16.
 */

public class PhoneActivity extends AppCompatActivity implements View.OnClickListener{
    private EditText phonenumber;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.phonelayout);
        initView();
    }

    private void initView() {
        Button button=findViewById(R.id.bt_search);
        button.setOnClickListener(this);
        phonenumber=findViewById(R.id.et_phone);
    }

    @Override
    public void onClick(View view) {
        int id=view.getId();
        switch (id){
            case R.id.bt_search:
                String number = phonenumber.getText().toString();
                if(number.length()==11){
                    Intent intent = new Intent(this,PhoneResult.class);
                    Bundle bundle = new Bundle();
                    bundle.putString("number", number);
                    intent.putExtras(bundle);
                    startActivity(intent);
                } else{
                    Toast.makeText(this,"您输入号码长度有误，请重新输入",Toast.LENGTH_SHORT).show();
                }
                break;
        }
    }
}
